package com.cdpowernode.pncrm.filter;

import com.cdpowernode.pncrm.javabean.User;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * @author jy
 * @version 1.0
 * @date 2021/12/4 14:44
 *
**/


/*
public class LoginFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
    }

    @Override
    public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException, ServletException {
        System.out.println("进入到验证有无登录过的过滤器");

        HttpServletRequest request = (HttpServletRequest) req;
        HttpServletResponse response = (HttpServletResponse) resp;

        HttpSession session = request.getSession();
        User user = (User) session.getAttribute("user");

        String path = request.getServletPath();
        String[] urls = {".js",".png",".css",".ico",".jpg"};
        if ("/index.jsp".equals(path) || "/settings/qx/user/toLogin".equals(path) || "/settings/qx/user/main".equals(path)){
            chain.doFilter(req,resp);
        }
//        boolean flag = true;


        else {
            //如果user不为空，说明登录过
            if (user != null){
                //放行
                chain.doFilter(req,resp);
            }else {
                //否则没有登陆过，拦截,重定向到登录页
                response.sendRedirect("/settings/qx/user/toLogin");
            }
        }
    }

    @Override
    public void destroy() {
    }
}
*/
